# encoding=utf-8

# sys.path.append("../main")
# https://blog.csdn.net/songzhilian22/article/details/49636725
# https://www.libinx.com/2018/text-classification-classic-ml-by-sklearn/

import os

import pandas as pd

os.path

import src.core.PandasUtils as pandasutils
import src.core.CacheUtils as cacheutils

data = pd.read_csv("../../data/training.csv")

values = data.values
# values = data.values

# 做数据的特征工程
path = '../../dist/train_data_full_2.pkl'
if cacheutils.model_exist(path):
    print("load model from ", path)
    df = cacheutils.load_model(path)
else:
    print("start data conversion")
    df = pandasutils.convert2KeywordsDataframs(values)
    cacheutils.save_model(df, path)

# print(df["X"])
# print(df["y"])

import src.core.train as mytrain
import numpy as np

y_train = df["y"]
X_train = df["X"]

# 训练样本6w+，交叉验证太慢，用train_test_split估计模型性能
from sklearn.model_selection import train_test_split

X_train_part, X_val, y_train_part, y_val = train_test_split(X_train, y_train, train_size=0.8, random_state=0)

print(X_train_part.shape)
print(X_val.shape)

#X_train_part = np.array(X_train_part)

print(">>>> SVM")
#model = mytrain.fit_svm(X_train_part, y_train_part)
#mytrain.printmetrics(model, X_val, y_val)

print(">>>> LR")
#model2 = mytrain.fit_LR(X_train_part, y_train_part)
#mytrain.printmetrics(model2, X_val, y_val)

print(">>>> XGBOOST")
model3 = mytrain.fit_xgb(np.array(X_train), y_train)
mytrain.printmetrics(model3, X_train, y_train)
